#include <stdio.h>
#include <signal.h>
#include <unistd.h>

void sigcb(int signum)
{
    printf("catch a signal %d\n", signum);
}

int main()
{
    struct sigaction sa;

    // 设置sigaction结构体
    sa.sa_handler = sigcb;
    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);

    // 注册SIGINT信号的处理函数
    int ret = sigaction(SIGINT, &sa, NULL);
    if(ret == -1) {
        perror("sigaction");
        return 1;
    }

    printf("waiting for signal...\n");

    // 无限循环，等待信号
    while(1) {
        sleep(1);
    }

    return 0;
}   
